package com.example.foobar.controller;

import com.example.foobar.business.service.DaConfigService;
import com.example.foobar.entity.DaConfig;
import com.example.foobar.dao.service.DaConfigDaoService;
import lombok.extern.slf4j.Slf4j;
import com.example.foobar.param.DaConfigPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 分析系统配置文件 控制器
 *
 * @author 郑英奔
 * @since 2021-05-31
 */
@Slf4j
@RestController
@RequestMapping("/daConfig")
@Module("daConfigController")
@Api(value = "分析系统配置文件API", tags = {"分析系统配置文件"})
public class DaConfigController extends BaseController {

    @Autowired
    private DaConfigService daConfigService;

    /**
     * 添加数据分析系统配置文件
     */
    @PostMapping("/add")
    @OperationLog(name = "添加分析系统配置文件", type = OperationLogType.ADD)
    @ApiOperation(value = "添加分析系统配置文件", response = ApiResult.class)
    public ApiResult<Boolean> addDaConfig(@Validated(Add.class) @RequestBody DaConfig daConfig) throws Exception {
        boolean flag = daConfigService.saveDaConfig(daConfig);
        return ApiResult.result(flag);
    }

    /**
     * 修改分析系统配置文件
     */
    @PostMapping("/update")
    @OperationLog(name = "修改分析系统配置文件", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改分析系统配置文件", response = ApiResult.class)
    public ApiResult<Boolean> updateDaConfig(@Validated(Update.class) @RequestBody DaConfig daConfig) throws Exception {
        boolean flag = daConfigService.updateDaConfig(daConfig);
        return ApiResult.result(flag);
    }

    /**
     * 删除分析系统配置文件
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除分析系统配置文件", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除分析系统配置文件", response = ApiResult.class)
    public ApiResult<Boolean> deleteDaConfig(@PathVariable("id") Long id) throws Exception {
        boolean flag = daConfigService.deleteDaConfig(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取分析系统配置文件详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "分析系统配置文件详情", type = OperationLogType.INFO)
    @ApiOperation(value = "分析系统配置文件详情", response = DaConfig.class)
    public ApiResult<DaConfig> getDaConfig(@PathVariable("id") Long id) throws Exception {
        DaConfig daConfig = daConfigService.getById(id);
        return ApiResult.ok(daConfig);
    }

    /**
     * 分析系统配置文件分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "分析系统配置文件分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "分析系统配置文件分页列表", response = DaConfig.class)
    public ApiResult<Paging<DaConfig>> getDaConfigPageList(@Validated @RequestBody DaConfigPageParam daConfigPageParam) throws Exception {
        Paging<DaConfig> paging = daConfigService.getDaConfigPageList(daConfigPageParam);
        return ApiResult.ok(paging);
    }

}

